// 获取静态资源地址
export function getImageUrl(name) {
  return new URL(`../assets/image/${name}`, import.meta.url).href
}

// 防抖
export function debounce(fn, delay = 1000) {
  let timer = null
  return function (...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}

// 节流
export function throttle(fn, delay = 1000) {
  let timer = null
  return function (...args) {
    if (timer) {
      return
    }
    timer = setTimeout(() => {
      fn.apply(this, args)
      timer = null
    }, delay)
  }
}
